package com.ss.common.util;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
//输出JSON流工具
public class JsonUtil {
	public static void outputJson(List list, HttpServletResponse response) throws IOException{
		JSONArray json = JSONArray.fromObject(list);
		response.setCharacterEncoding("UTF-8");
		response.setContentType( "application/json; charset=UTF-8" );
		response.getWriter().print(json.toString());
	}
	
	public static void outputJson(Object obj, HttpServletResponse response) throws IOException{
		JSONObject json = JSONObject.fromObject(obj);
		response.setCharacterEncoding("UTF-8");
		response.setContentType( "application/json; charset=UTF-8" );
		response.getWriter().print(json.toString());
	}
	
	
	public static String  convert(String value){
		if(value==null){
			value="0";
		}
		double d=new Double(value)*100;
		DecimalFormat df=new DecimalFormat("0.00");
		String returnval=df.format(d)+"%";
		
		return returnval;
		
	}
}
